import com.github.pagehelper.PageInfo;
import com.hc.pojo.TbUser;
import com.hc.service.TbUserService;
import com.hc.service.impl.TbUserServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class testUser {
    @Test
    public void testU(){
       /* String re="MybatisConfig.xml";
        InputStream in=testUser.class.getClassLoader().getResourceAsStream(re);
       *//* try {
            in = Resources.getResourceAsStream(resouce);
        }catch (Exception e){

            e.getStackTrace();
        }*//*
        System.out.println(in);
        SqlSessionFactory sessionFactory;
        sessionFactory = new SqlSessionFactoryBuilder().build(in);

        SqlSession session=sessionFactory.openSession();*/
       /* SqlSession session= MybatisUtils.getSqlSession();
        UserMapper um=session.getMapper(UserMapper.class);

        TbUser tbUser=um.selectByEmail("1234@123.com");

        System.out.println(tbUser);
        String pwd=DigestUtils.md5Hex("123456");
        boolean b=tbUser.getPassword().equals(pwd);
        System.out.println(b);*/

        /* TbUser user=um.findByid(7);
        System.out.println(user);

        Date date=new Date();
        TbUser us=new TbUser("张三",pwd,"9876577777","1234@123.com",date,new Date());
        System.out.println(us);
        um.addTbUser(us);
        session.commit();
        System.out.println(um.findByid(us.getId()));*/
       /* Map<String,String> map=new HashMap<String, String>();
        map.put("search","");
        map.put("username","柳柳");
        map.put("phone","98");
        map.put("email","");
        List<TbUser> list=um.findLike(map);
        if(list!=null && (list.size()!=0))
        for(TbUser tu:list){
            System.out.println(tu);
        }*/

        TbUserService service=new TbUserServiceImpl();
        TbUser user=service.selectEmailAndPassWord("1234@123.com");

        List<TbUser> list=service.findAll();

        String pwd=DigestUtils.md5Hex("123456");
        TbUser us=service.findById((long) 16);
//        boolean bool=service.addUser(us);
        us.setUserName("王潇潇");
        us.setEmail("8954@gg.cn");
        int i=service.updateTbUer(us);
    }

    @Test
    public void testadd(){
        TbUser user=new TbUser();
        user.setUserName("主要要");
        user.setPassword("123456");
        user.setPhone("85651238");
        user.setEmail("85dh@kskd");
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        TbUserService service=new TbUserServiceImpl();
        boolean bool=service.addUser(user);
        long id=user.getId();




    }

    @Test
    public void testLike() {
        TbUserService service = new TbUserServiceImpl();
        Map<String, String> map = new HashMap<String, String>();
        map.put("search", null);
        map.put("username", "");
        map.put("phone", "987");
        map.put("email", "123");
        List<TbUser> list = service.likeSearch(map);
        int i=list.size();
        TbUser user=new TbUser();
    }

    @Test
    public void addUserText(){
        TbUserService service=new TbUserServiceImpl();
       /* for(int i=5;i<98;i++){
            TbUser user=new TbUser();
            user.setUserName("zhangsan"+(i+1));
            user.setPassword(DigestUtils.md5Hex("123456"));
            user.setPhone(123856458+i+"");
            user.setEmail("123"+i+"@123.com");
            boolean bool=service.addUser(user);
        }*/
        PageInfo info=service.listUserByPage(1,10);
        System.out.println(info);
    }
}
